<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true">
      <el-form-item label="关键字">
        <el-input v-model="keyword" placeholder="姓名/手机/身份证" />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getBorrowerList()">
        查询
      </el-button>
      <el-button type="default" @click="resetData()">
        清空
      </el-button>
    </el-form>

    <!-- 列表 -->
    <el-table :data="list" stripe>
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="姓名" />
      <el-table-column prop="mobile" label="手机" />
      <el-table-column prop="idCard" label="身份证号" width="200" />
      <el-table-column label="性别" width="80">
        <template slot-scope="scope">
          {{ scope.row.sex === 1 ? '男' : '女' }}
        </template>
      </el-table-column>

      <el-table-column prop="age" label="年龄" width="80" />

      <el-table-column label="是否结婚" width="120">
        <template slot-scope="scope">
          {{ scope.row.marry ? '是' : '否' }}
        </template>
      </el-table-column>

      <el-table-column label="状态" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" type="info" size="mini">
            未认证
          </el-tag>
          <el-tag v-if="scope.row.status === 1" type="warning" size="mini">
            认证中
          </el-tag>
          <el-tag v-if="scope.row.status === 2" type="success" size="mini">
            认证通过
          </el-tag>
          <el-tag v-if="scope.row.status === -1" type="danger" size="mini">
            认证失败
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column prop="createTime" label="申请时间" width="160" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/core/borrower/detail/' + scope.row.id">
            <el-button v-if="scope.row.status === 1" type="warning" size="mini">
              审批
            </el-button>
            <el-button v-else type="primary" size="mini">
              查看
            </el-button>
          </router-link>
        </template>
      </el-table-column>

      <!-- 审批对话框 -->
      <el-dialog title="审批" :visible.sync="dialogVisible" width="490px">
        <el-form label-position="right" label-width="100px">
          <el-form-item label="是否通过">
            <el-radio-group v-model="borrowInfoApproval.status">
              <el-radio :label="2">通过</el-radio>
              <el-radio :label="-1">不通过</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item v-if="borrowInfoApproval.status == 2" label="标的名称">
            <el-input v-model="borrowInfoApproval.title" />
          </el-form-item>

          <el-form-item v-if="borrowInfoApproval.status == 2" label="起息日">
            <el-date-picker
              v-model="borrowInfoApproval.lendStartDate"
              type="date"
              placeholder="选择开始时间"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>

          <el-form-item v-if="borrowInfoApproval.status == 2" label="年化收益率">
            <el-input v-model="borrowInfoApproval.lendYearRate">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>

          <el-form-item v-if="borrowInfoApproval.status == 2" label="服务费率">
            <el-input v-model="borrowInfoApproval.serviceRate">
              <template slot="append">%</template>
            </el-input>
          </el-form-item>

          <el-form-item v-if="borrowInfoApproval.status == 2" label="标的描述">
            <el-input v-model="borrowInfoApproval.lendInfo" type="textarea" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">
            取消
          </el-button>
          <el-button type="primary" @click="approvalSubmit">
            确定
          </el-button>
        </div>
      </el-dialog>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      :page-sizes="[2, 10, 20]"
      style="padding: 30px 0; "
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="changePageSize"
      @current-change="changeCurrentPage"
    />
  </div>
</template>
<script>
  // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  import borrowerApi from '@/api/core/borrower'

  // 例如: import《组件名称》from'《组件路径》';
  export default {
  // import引入的组件需要注入到对象中才能使用
    components: {},
    props: {},
    data () {
  // 这里存放数据
      return {
        list: null, // banner列表
        total: 0, // 数据库中的总记录数
        page: 1, // 默认页码
        limit: 10, // 每页记录数
        keyword: '', // 查询表单对象
      };
    },
  // 计算属性类似于data概念
    computed: {},
  // 监控data中的数据变化
    watch: {},
  // 方法的集合
    methods: {
      getBorrowerList() {
        borrowerApi.getBorrowerList(this.page,this.limit,this.keyword).then(response => {
          this.list = response.data.pageModel.records;
          this.total = response.data.pageModel.total
        })
      },

      resetData() {
        this.keyword = ''
        this.getBorrowerList()
      },

      // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
      changePageSize(size) {
        this.limit = size
        this.getBorrowerList()
      },

      // 改变页码，page：回调参数，表示当前选中的“页码”
      changeCurrentPage(page) {
        this.page = page
        this.getBorrowerList()
      },
    },
  // 生命周期-创建完成(可以访问当前this实例
    created () {
      this.getBorrowerList()
    },
  // 生命周期-挂载完成(可以访问poM元素
    mounted () {

    },
    // 生命周期-创建之前
    beforeCreate () {
    },
    // 生命周期-挂载之前
    beforeMount () {
    },
    // 生命周期-更新之前
    beforeUpdate () {
    },
    // 生命周期-更新之后
    updated () {
    },
    // 生命周明-销毁之前
    beforeDestroy () {
    },
    // 生命周期-销毁完成
    destroyed () {
    },
    // 如果页面有keep- alive缓存功能,这个函数会触发
    activated () {
    }
  }
</script>
<style scoped>

</style>
